{
  "properties" : { },
  "id" : "a4b7a9007f974a43ab4467aa52f30e4e",
  "script" : null,
  "groupId" : "d855b1e94eaf41d194921f70cc815ae3",
  "name" : "获取站点信息",
  "createTime" : 1718810328462,
  "updateTime" : 1715597290370,
  "lock" : null,
  "createBy" : "管理员",
  "updateBy" : "管理员",
  "path" : "getSiteInfo",
  "description" : null,
  "returnType" : null,
  "mappingPath" : null,
  "parameters" : [ {
    "name" : "webIcpUrl",
    "value" : null,
    "description" : "",
    "required" : false,
    "dataType" : "String",
    "type" : "java.lang.String",
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "webXpath",
    "value" : null,
    "description" : "",
    "required" : false,
    "dataType" : "String",
    "type" : "java.lang.String",
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  } ]
}
================================
import java.io.File

import org.ssssssss.magicapi.utils.IoUtils
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.OutputType
import org.openqa.selenium.By
import org.openqa.selenium.WebElement
import org.openqa.selenium.firefox.FirefoxOptions
import org.openqa.selenium.firefox.FirefoxProfile
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.Cookie
import response

// -- 配置
System.setProperty("webdriver.gecko.driver", "D:/data/spider/file/geckodriver.exe");
var options = new FirefoxOptions();
// -- 启动
FirefoxDriver driver = new FirefoxDriver(options);
 // 设置页面加载超时时间
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
// 设置异步脚本执行超时时间
driver.manage().timeouts().setScriptTimeout(5, TimeUnit.SECONDS);

// -- 获取
var webTitle;
var webImg;
var webOpenUrl;
var state = 1;

try {
    driver.get("http://"+webIcpUrl);
} catch(e) {
    driver.close();
    try {
        driver.get("https://"+webIcpUrl);
    } catch(e) {
        state = 0;
        return {'name': webTitle, 'icp_url': webIcpUrl, 'open_url': webOpenUrl, 'img_byte': webImg, 'state': state, 'xpath': webXpath}
    }
}
try {
    // -- 动作
    weAct = new Actions(driver).pause(6*1000).perform();
    webTitle = driver.getTitle();
    webOpenUrl = driver.getCurrentUrl();

    // -- 取元素
    WebElement we = driver.findElement(By.xpath(webXpath));
    // -- 截图元素
    /*
    try {
        webImg = we.getScreenshotAs(OutputType.BYTES);
    } catch(e) {
        state = 0;
        webImg = driver.getScreenshotAs(OutputType.BYTES)
    }
    */
    webImg = driver.getScreenshotAs(OutputType.BYTES);

    var inputFile = new File('/data/png/'+webIcpUrl.replace('.', '_')+'.png');
    IoUtils.write(inputFile, webImg);
} catch(e) {
    state = 0;
} finally {
    // -- 结束
    try {
        driver.close();
    } catch(e) {
        state = 0;
    }
}

if(webTitle && webTitle.length()> 60){
    webTitle = webTitle.substring(0, 61);
}

return {'name': webTitle, 'icp_url': webIcpUrl, 'open_url': webOpenUrl, 'img_byte': webImg, 'state': state, 'xpath': webXpath}